#include "types.h"
#include "riscv.h"
#include "defs.h"

#define BACKSPACE 0x100

//
// send one character to the uart.
// called by printf(), and to echo input characters,
// but not from write().
//
void
consputc(int c)
{
  // 键盘退格键c=0x7f, xv6是在consoleintr()里处理后转成BACKSPACE的
  if(c == BACKSPACE || c == 0x7f){
    // 为了实现退格功能，函数会发送三个连续的字符到串口
    // if the user typed backspace, overwrite with a space.
    // '\b': 光标后移一格. 输出空格后光标会后移, 因此需要'\b'再次后退一格
    uartputc_sync('\b'); uartputc_sync(' '); uartputc_sync('\b');
  } else {
    uartputc_sync(c);
  }
}
